package com.spagettikod.t437.simpledb;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import com.spagettikod.t437.T437;

public class AttributeRenderer extends JLabel implements TableCellRenderer
{

	private static final long serialVersionUID = -4525018746484867477L;

	public AttributeRenderer()
	{
		super();
		setOpaque(true);
	}

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column)
	{
		SimpleDBAttribute attr = (SimpleDBAttribute) value;
		if (attr == null)
		{
			setText("");
		}
		else
		{
			setText(attr.toString());
			if (attr.hasMultipleValues() && T437.getConfigurator().getSDBMultipleBackgroundColorize())
			{
				setBackground(Color.YELLOW);
			}
			else
			{
				setBackground(Color.WHITE);
			}
		}
		return this;
	}

}
